package com.bds.wm.utils;

import org.springframework.util.StringUtils;

import java.text.DecimalFormat;

/**
 * Created by DongChenchen on 2018/5/28 0028
 */
public class FormatUils {
    private final static DecimalFormat df = new DecimalFormat("#,###.0");
    private final static DecimalFormat df2 = new DecimalFormat("#0.0");
    private final static DecimalFormat df3 = new DecimalFormat("#,###");

    /**
     * 金额格式
     * @param nums Integer Double String
     * @return
     */
    public static String formatConv(Object nums){
        return formatConv(nums,-1);
    }
    public static String formatConv(Object nums,Integer divid){
        Double num =0.0;
        if(nums instanceof String) {
            if (StringUtils.isEmpty(nums)) {
                return df2.format(0);
            }
            num = Double.valueOf((String)nums);
        }else if (nums instanceof Double){
            num = (double) nums;
        }else if(nums instanceof Integer){
            return df3.format(nums);
        }
        if(divid!=-1) {
            num = num / divid;
        }
        if(num>1000){
            return df.format(num);
        }else{
            return df2.format(num);
        }
    }
    public static String formatConvmax(Object nums){
        return formatConmax(nums,-1);
    }
    public static String formatConmax(Object nums,Integer divid){
        Double num =0.0;
        if(nums instanceof String) {
            if (StringUtils.isEmpty(nums)) {
                return df2.format(0);
            }
            num = Double.valueOf((String)nums);
        }else if (nums instanceof Double){
            num = (double) nums;
        }else if(nums instanceof Integer){
            return df3.format(nums);
        }
        if(divid!=-1) {
            num = num / divid;
        }
        if(num>1000){
            return df3.format(num);
        }else{
            return df3.format(num);
        }
    }
}
